顯示星期幾範例:
開始產生變數
強制轉換型態
int iVk = Convert.ToInt32(numericUpDown1.Value);
再來是switch
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace _20210410
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
numericUpDown1.Maximum = 7;
numericUpDown1.Minimum = 1;
Lab_1.Text = Lab_2.Text = Lab_3.Text = "";
}
private void NumericUpDown1_ValueChanged(object sender, EventArgs e)
{
int iVk = Convert.ToInt32(numericUpDown1.Value);
switch(iVk)
{
case 1:
Lab_1.Text = "Monday";Lab_2.Text = "Mon";Lab_3.Text = "月曜日";
break;
case 2:
Lab_1.Text = "Tuesday"; Lab_2.Text = "Tue"; Lab_3.Text = "火曜日";
break;
case 3:
Lab_1.Text = "Wednesday"; Lab_2.Text = "Wed"; Lab_3.Text = "水曜日";
break;
case 4:
Lab_1.Text = "Thursday"; Lab_2.Text = "Thu"; Lab_3.Text = "木曜日";
break;
case 5:
Lab_1.Text = "Friday"; Lab_2.Text = "Fri"; Lab_3.Text = "金曜日";
break;
case 6:
Lab_1.Text = "Sturday"; Lab_2.Text = "Sat"; Lab_3.Text = "土曜日";
break;
case 7:
Lab_1.Text = "Sunday"; Lab_2.Text = "Sun"; Lab_3.Text = "日曜日";
break;
}
}
}
}
清單方塊
選Items會有集合可以輸入
MultColum就可以顯示多欄
selectionmode顯示單選/複選
做課程選取清單
checklistbox的checkon..要是flase才可以作動
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace _2021041002
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
cklstbx.CheckOnClick = true;
cklstbx.Items.Add("JAVA");
}
}
}
新增課程
記得不要多點兩下..才不會要刪程式碼
同樣資料輸入用"陣列"Array輸入
Length長度
宣告語法:
陣列型態 || 陣列名稱 =new 型態 [陣列長度];
int || iA =new int[5];
指定陣列初始值
int || iA =[59,83,62,91,98];
陣列名稱[索引值]:從0開始等差1
變比較少字的code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace _2021041002
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
cklstbx.CheckOnClick = true;
string[] sElt = { "還是JAVA" };
for (int i = 0; i < sElt.Length; i++)
{ cklstbx.Items.Add(sElt[i]); }
}
}
}
while前測試迴圈(這次要不要執行)
語法:
初始狀態(起始值);
while(迴圈執行條件)
{迴圈程式區段;
狀態變化(值變方式);
}
int i=0;
while(i< sElt.Length)
{ cklstbx.Items.Add(sElt[i++]); }
do...while迴圈(下次要不要執行)執行到do會繼續執行
語法:
初始狀態(起始值);
do
{
迴圈程式區段;
狀態變化(值變方式);
}while(執行條件);分號
顯示選了幾科
listbox和checklist box
的selectindexchanged開始用
產生副程式 來計算
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace _2021041002
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
cklstbx.CheckOnClick = true;
string[] sElt = { "還是JAVA" };
//for (int i = 0; i < sElt.Length; i++)
//{ cklstbx.Items.Add(sElt[i]); }
int i = 0;
while (i < sElt.Length)
{ cklstbx.Items.Add(sElt[i++]); }
vItmCnt();
}
private void Cklstbx_SelectedIndexChanged(object sender, EventArgs e)
{
vItmCnt();
}
private void vItmCnt()
{
int iItmCnt = cklstbx.Items.Count; //取得清單總數
int iCkItmCnt = cklstbx.CheckedItems.Count; //取得清單總數
lab_Cnt.Text = iCkItmCnt + "/" + iItmCnt;
}
}
}
讓勾選的顯示在下面
do...while迴圈(下次要不要執行)執行到do會繼續執行
語法:
初始狀態(起始值);
do
{
迴圈程式區段;
狀態變化(值變方式);
}while(執行條件);分號
把int iCkItmCnt提到範圍外do..while迴圈才可以使用
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace _2021041002
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
int iCkItmCnt;
private void Form1_Load(object sender, EventArgs e)
{
cklstbx.CheckOnClick = true;
string[] sElt = { "還是JAVA" };
//for (int i = 0; i < sElt.Length; i++)
//{ cklstbx.Items.Add(sElt[i]); }
int i = 0;
while (i < sElt.Length)
{ cklstbx.Items.Add(sElt[i++]); }
vItmCnt();
}
private void Cklstbx_SelectedIndexChanged(object sender, EventArgs e)
{
vItmCnt();
}
private void vItmCnt()
{
int iItmCnt = cklstbx.Items.Count; //取得清單總數
iCkItmCnt = cklstbx.CheckedItems.Count; //取得清單總數
lab_Cnt.Text = iCkItmCnt + "/" + iItmCnt;
}
private void Btn_Add_Click(object sender, EventArgs e)
{
int i = 0;
do
{
litbx.Items.Add(cklstbx.CheckedItems[i]);
} while (++i<iCkItmCnt);
}
}
}
加入沒有V時才部會出現錯誤
litbx.Items.Clear();
int i = 0;
if(iCkItmCnt>0)
{
do
{
litbx.Items.Add(cklstbx.CheckedItems[i]);
} while (++i < iCkItmCnt);
}
}
變成
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace _2021041002
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
int iCkItmCnt;
private void Form1_Load(object sender, EventArgs e)
{
cklstbx.CheckOnClick = true;
string[] sElt = { "還是JAVA" };
//for (int i = 0; i < sElt.Length; i++)
//{ cklstbx.Items.Add(sElt[i]); }
int i = 0;
while (i < sElt.Length)
{ cklstbx.Items.Add(sElt[i++]); }
vItmCnt();
}
private void Cklstbx_SelectedIndexChanged(object sender, EventArgs e)
{
vItmCnt();
}
private void vItmCnt()
{
int iItmCnt = cklstbx.Items.Count; //取得清單總數
iCkItmCnt = cklstbx.CheckedItems.Count; //取得清單總數
lab_Cnt.Text = iCkItmCnt + "/" + iItmCnt;
}
private void Btn_Add_Click(object sender, EventArgs e)
{
litbx.Items.Clear();
int i = 0;
if(iCkItmCnt>0)
{
do
{
litbx.Items.Add(cklstbx.CheckedItems[i]);
} while (++i < iCkItmCnt);
}
}
}
}
雖然網路上用LINE Bot實作的資料應該很多~
但是為了讓我自己練習一下
所以~還是排入
還有11天到時補坑應該來得及
預計寫的內容如下:
1.透過簡單的命令列嘗試發送訊息
2.嘗試透過C#程式碼發送文字、貼圖、和圖…
3.如何使用Visual Studio 2019與LineBotSDK套件
4.關於template message
5. Hands-on Lab :如何發送卡片格式的Template Messages
6. .....
DEAR ALL 我們明天見